Skip to content

Fix #14607: MISRA: make rule 10.3 warn on bool <- 0/1 in C99 and later#8340

Open
varshneydevansh wants to merge 1 commit intodanmar:mainfrom
varshneydevansh:misra
Open

Fix #14607: MISRA: make rule 10.3 warn on bool <- 0/1 in C99 and later#8340
varshneydevansh wants to merge 1 commit intodanmar:mainfrom
varshneydevansh:misra

Conversation

@varshneydevansh
Copy link

@varshneydevansh varshneydevansh commented Mar 15, 2026

Fix #14607.

This updates MISRA rule 10.3 in addons/misra.py so that assignments of integer literals 0 and 1 to bool are only exempted in C89.

Behavior after this change:

  • C89: keep the existing behavior and allow bool <- 0/1
  • C99/C11/C17/C18/C23: report MISRA 10.3 for bool <- 0/1

The motivation is that in C99 and later, bool/true/false are available, so the current unconditional exemption for 0 and 1 causes a MISRA 10.3 false negative.

Changes:

  • update addons/misra.py rule 10.3 to make the bool <- 0/1 exemption standard-dependent
  • add C89-side coverage in addons/test/misra/misra-test.c
  • add C11-side coverage in addons/test/misra/misra-test-c11.c
  • add a release notes entry

Related Context:

@varshneydevansh
Copy link
Author

varshneydevansh commented Mar 15, 2026

Trac ticket is now filed: https://trac.cppcheck.net/ticket/14607

Local verification passed:

  • misra.py -verify for misra-test.c with --std=c89
  • misra.py -verify for misra-test-c11.c with --std=c11
  • PYTHONPATH=./addons .venv/bin/python -m pytest addons/test/misra_test.py

@sonarqubecloud
Copy link

@varshneydevansh varshneydevansh changed the title feat: misra: make rule 10.3 warn on bool <- 0/1 in C99 and later Fix #14607: MISRA: make rule 10.3 warn on bool <- 0/1 in C99 and later Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant